package com.itheima.controller;

import com.itheima.vo.req.LoginReqVo;
import com.itheima.vo.resp.LoginRespVo;
import com.itheima.vo.resp.R;
import com.itheima.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/api")
@Api("用户管理")
public class UserController {
    @Autowired
    UserService userService;

    /**
     * 用户登录
     * @param reqVo
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("用户登录")
    public R<LoginRespVo> login(@RequestBody LoginReqVo reqVo){
        log.info("用户登录：{}",reqVo);
        return userService.login(reqVo);
    }

    /**
     * ⽣成登录校验码的访问接⼝
     * @return
     */
    @GetMapping("/captcha")
    @ApiOperation("生成验证码")
    public R<Map> getCaptchaCode(){
        Map map = userService.getCaptchaCode();
        log.info("生成验证码:{}",map);
        return R.ok(map);
    }

}
